//
//  InformationDetailsViewController.m
//  Againstpoor
//
//  Created by 辰领科技 on 16/11/6.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "InformationDetailsViewController.h"

@interface InformationDetailsViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroview;
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *genderLabel;
@property (weak, nonatomic) IBOutlet UILabel *ageLabel;
@property (weak, nonatomic) IBOutlet UILabel *ethnicLabel;
@property (weak, nonatomic) IBOutlet UILabel *cultureLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *RelationshipLabel;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UILabel *attributeLabel;
@property (weak, nonatomic) IBOutlet UILabel *whyLaebl;
@property (weak, nonatomic) IBOutlet UILabel *secondaryWhyLabel;
@property (weak, nonatomic) IBOutlet UILabel *AnnualIncomeLabel;
@property (weak, nonatomic) IBOutlet UILabel *incomeLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumberLaebl;

@property (strong, nonatomic) NSDictionary *Dic;

@end

@implementation InformationDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _Dic = [NSDictionary dictionary];
    [self initViewLayout];
    [self getFileDetails];
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.scroview.contentSize = flexibleSize(CGSizeMake(0, 504.1), NO);
    
}

- (IBAction)back:(id)sender {
    [self backBtn];
}
#pragma mark - 提交
- (IBAction)submit:(id)sender {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"lat"] forKey:@"lat"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"lng"] forKey:@"lng"];
    [dic setObject:_AAC001 forKey:@"aac001"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_saveFarmerPosition withHttpType:@"POST" withTag:F_F_saveFarmerPosition];
}

#pragma mark - 档案详情
- (void)getFileDetails {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:_AAC001 forKey:@"id"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_farmerDetail withHttpType:@"POST" withTag:F_F_farmerDetail];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==F_F_farmerDetail) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            _Dic = database[@"data"];
            
            NSString *image = [NSString stringWithFormat:@"%@",[Common stringFromData:_Dic[@"image"]]];
            if (image && image.length>0 && ![[Common stringFromData:_Dic[@"image"]] isEqual:[NSNull null]]) {
                [_image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
            }
            _nameLabel.text = [NSString stringWithFormat:@"贫困户：%@",_Dic[@"NAME"]];
            NSInteger AAB003 = [_Dic[@"AAB003"] integerValue];
            if (AAB003 == 1) {
                _genderLabel.text = @"性别：男";
            } else if (AAB003 == 2) {
                _genderLabel.text = @"性别：女";
            }
            _ageLabel.text = [NSString stringWithFormat:@"年龄：%@",_Dic[@"AGE"]];
            _ethnicLabel.text = [NSString stringWithFormat:@"名族：%@",[self ethnic:[NSString stringWithFormat:@"%@",_Dic[@"AAB007"]]]];
            _cultureLabel.text = [NSString stringWithFormat:@"文化程度：%@",[self RecordOfFormalSchooling:[NSString stringWithFormat:@"%@",_Dic[@"AAB008"]]]];
            
            _addressLabel.text = [NSString stringWithFormat:@"%@%@",_Dic[@"area"],_Dic[@"country"]];
            _numberLabel.text = [Common stringFromData:_Dic[@"size"]];
            NSInteger AAC006 = [_Dic[@"AAC006"] integerValue];
            if (AAC006 == 01) {
                _attributeLabel.text = @"一般困难户";
            } else if (AAC006 == 02) {
                _attributeLabel.text = @"低保户";
            } else if (AAC006 == 03) {
                _attributeLabel.text = @"五保户";
            } else if (AAC006 == 04) {
                _attributeLabel.text = @"低保困难户";
            } else if (AAC006 == 05) {
                _attributeLabel.text = @"一般农户";
            }
            _whyLaebl.text = [self mainReason:[NSString stringWithFormat:@"%@",_Dic[@"AAC007"]]];
            _secondaryWhyLabel.text = [self secondaryReason:[NSString stringWithFormat:@"%@",_Dic[@"AAC008"]]];
            _AnnualIncomeLabel.text = [Common stringFromData:_Dic[@"AAC079"]];
            _incomeLabel.text = [Common stringFromData:_Dic[@"AAC082"]];
            _phoneNumberLaebl.text = [NSString stringWithFormat:@"联系电话：%@",_Dic[@"AAR012"]];
        }else  {
        }
    } else if (tag==F_F_saveFarmerPosition) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            [[CWHUDTips sharedInstance]  showTips:database[@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }else  {
            [[CWHUDTips sharedInstance]  showTips:database[@"msg"]  withStatus:1 dismissAfter:1.5];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}

- (NSString *)mainReason:(NSString *)value {
    NSString *str;
    if([value isEqualToString:@"01"]) {
        str = @"因病";
    }else if([value isEqualToString:@"02"]) {
        str = @"因残";
    }else if([value isEqualToString:@"03"]) {
        str = @"因学";
    }else if([value isEqualToString:@"04"]) {
        str = @"因灾";
    }else if([value isEqualToString:@"05"]) {
        str = @"缺土地";
    }else if([value isEqualToString:@"06"]) {
        str = @"缺水";
    }else if([value isEqualToString:@"07"]) {
        str = @"缺技术";
    }else if([value isEqualToString:@"08"]) {
        str = @"缺劳力";
    }else if([value isEqualToString:@"09"]) {
        str = @"缺资金";
    }else if([value isEqualToString:@"10"]) {
        str = @"交通条件落后";
    }else if([value isEqualToString:@"11"]) {
        str = @"自身发展动力不足";
    }else if([value isEqualToString:@"99"]) {
        str = @"其他";
    }
    return str;
}
- (NSString *)secondaryReason:(NSString *)value {
    NSString *str;
    if([value isEqualToString:@"01"]) {
        str = @"因病";
    }else if([value isEqualToString:@"02"]) {
        str = @"因残";
    }else if([value isEqualToString:@"03"]) {
        str = @"因学";
    }else if([value isEqualToString:@"04"]) {
        str = @"因灾";
    }else if([value isEqualToString:@"05"]) {
        str = @"缺土地";
    }else if([value isEqualToString:@"06"]) {
        str = @"缺水";
    }else if([value isEqualToString:@"07"]) {
        str = @"缺技术";
    }else if([value isEqualToString:@"08"]) {
        str = @"缺劳力";
    }else if([value isEqualToString:@"09"]) {
        str = @"缺资金";
    }else if([value isEqualToString:@"10"]) {
        str = @"交通条件落后";
    }else if([value isEqualToString:@"11"]) {
        str = @"自身发展动力不足";
    }else if([value isEqualToString:@"12"]) {
        str = @"婚姻";
    }else if([value isEqualToString:@"99"]) {
        str = @"其他";
    }
    return str;
}

- (NSString *)ethnic:(NSString *)value {
    NSString *str;
    if([value isEqualToString:@"01"]) {
        str = @"汉族";
    }else if([value isEqualToString:@"02"]) {
        str = @"满族";
    }else if([value isEqualToString:@"03"]) {
        str = @"回族";
    }else if([value isEqualToString:@"04"]) {
        str = @"蒙古族";
    }else if([value isEqualToString:@"05"]) {
        str = @"藏族";
    }else if([value isEqualToString:@"06"]) {
        str = @"维吾尔族";
    }else if([value isEqualToString:@"07"]) {
        str = @"苗族";
    }else if([value isEqualToString:@"08"]) {
        str = @"彝族";
    }else if([value isEqualToString:@"09"]) {
        str = @"壮族";
    }else if([value isEqualToString:@"10"]) {
        str = @"布依族";
    }else if([value isEqualToString:@"11"]) {
        str = @"朝鲜族";
    }else if([value isEqualToString:@"12"]) {
        str = @"侗族";
    }else if([value isEqualToString:@"13"]) {
        str = @"瑶族";
    }else if([value isEqualToString:@"14"]) {
        str = @"白族";
    }else if([value isEqualToString:@"15"]) {
        str = @"土家族";
    }else if([value isEqualToString:@"16"]) {
        str = @"哈尼族";
    }else if([value isEqualToString:@"17"]) {
        str = @"哈萨克族";
    }else if([value isEqualToString:@"18"]) {
        str = @"傣族";
    }else if([value isEqualToString:@"19"]) {
        str = @"黎族";
    }else if([value isEqualToString:@"20"]) {
        str = @"僳僳族";
    }else if([value isEqualToString:@"21"]) {
        str = @"佤族";
    }else if([value isEqualToString:@"22"]) {
        str = @"畲族";
    }else if([value isEqualToString:@"23"]) {
        str = @"高山族";
    }else if([value isEqualToString:@"24"]) {
        str = @"拉祜族";
    }else if([value isEqualToString:@"25"]) {
        str = @"水族";
    }else if([value isEqualToString:@"26"]) {
        str = @"东乡族";
    }else if([value isEqualToString:@"27"]) {
        str = @"纳西族";
    }else if([value isEqualToString:@"28"]) {
        str = @"景颇族";
    }else if([value isEqualToString:@"29"]) {
        str = @"柯尔克孜族";
    }else if([value isEqualToString:@"30"]) {
        str = @"土族";
    }else if([value isEqualToString:@"31"]) {
        str = @"达斡尔族";
    }else if([value isEqualToString:@"32"]) {
        str = @"仫佬族";
    }else if([value isEqualToString:@"33"]) {
        str = @"羌族";
    }else if([value isEqualToString:@"34"]) {
        str = @"布朗族";
    }else if([value isEqualToString:@"35"]) {
        str = @"撒拉族";
    }else if([value isEqualToString:@"36"]) {
        str = @"毛南族";
    }else if([value isEqualToString:@"37"]) {
        str = @"仡佬族";
    }else if([value isEqualToString:@"38"]) {
        str = @"锡伯族";
    }else if([value isEqualToString:@"39"]) {
        str = @"阿昌族";
    }else if([value isEqualToString:@"40"]) {
        str = @"普米族";
    }else if([value isEqualToString:@"41"]) {
        str = @"塔吉克族";
    }else if([value isEqualToString:@"42"]) {
        str = @"怒族";
    }else if([value isEqualToString:@"43"]) {
        str = @"乌孜别克族";
    }else if([value isEqualToString:@"44"]) {
        str = @"俄罗斯族";
    }else if([value isEqualToString:@"45"]) {
        str = @"鄂温克族";
    }else if([value isEqualToString:@"46"]) {
        str = @"德昂族";
    }else if([value isEqualToString:@"47"]) {
        str = @"保安族";
    }else if([value isEqualToString:@"48"]) {
        str = @"裕固族";
    }else if([value isEqualToString:@"49"]) {
        str = @"京族";
    }else if([value isEqualToString:@"50"]) {
        str = @"塔塔尔族";
    }else if([value isEqualToString:@"51"]) {
        str = @"独龙族";
    }else if([value isEqualToString:@"52"]) {
        str = @"鄂伦春族";
    }else if([value isEqualToString:@"53"]) {
        str = @"赫哲族";
    }else if([value isEqualToString:@"54"]) {
        str = @"门巴族";
    }else if([value isEqualToString:@"55"]) {
        str = @"珞巴族";
    }else if([value isEqualToString:@"56"]) {
        str = @"基诺族";
    }else if([value isEqualToString:@"99"]) {
        str = @"其他";
    }
    return str;
}

- (NSString *)RecordOfFormalSchooling:(NSString *)value {
    NSString *str;
    if([value isEqualToString:@"01"]) {
        str = @"文盲或半文盲";
    }else if([value isEqualToString:@"02"]) {
        str = @"小学";
    }else if([value isEqualToString:@"03"]) {
        str = @"初中";
    }else if([value isEqualToString:@"04"]) {
        str = @"高中";
    }else if([value isEqualToString:@"05"]) {
        str = @"大专及以上";
    }else if([value isEqualToString:@"06"]) {
        str = @"学龄前儿童";
    }
    return str;
}

@end
